<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="openSearch = true"
          >搜索</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['purchase:yp:export']"
        >
          导出
        </el-button>
      </el-col>
    </el-row>

    <el-table
      highlight-current-row
      border
      stripe
      v-loading="loading"
      :data="tableData.rows"
      id="tabYpReport"
      @scrollBottom="load"
      height="calc(100% - 100px)"
      :header-cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column label="#" width="40" type="index" align="center" />
      <el-table-column
        label="物料代码"
        width="150"
        :show-overflow-tooltip="true"
        align="center"
        prop="hmon_wldm"
      />
      <el-table-column
        label="物料品名"
        :show-overflow-tooltip="true"
        align="center"
        prop="itm_pmgg"
      />
      <el-table-column
        label="材料单价"
        width="150"
        :show-overflow-tooltip="true"
        align="center"
        prop="hmon_unit_price"
      />
      <el-table-column
        label="单位"
        :show-overflow-tooltip="true"
        width="60"
        align="center"
        prop="itm_dw"
      >
        <template #default="scope">
          <dict-tag :options="unitFlagOptions" :value="scope.row.itm_dw" />
        </template>
      </el-table-column>
      <el-table-column
        label="存放位置"
        align="center"
        prop="itm_cwdm"
        width="90"
      >
        <template #default="scope">
          <dict-tag :options="allStorageOptions" :value="scope.row.itm_cwdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="建立人员"
        width="150"
        :show-overflow-tooltip="true"
        align="center"
        prop="hmon_jlry"
      ></el-table-column>
      <el-table-column
        label="建立日期"
        width="150"
        align="center"
        prop="hmon_jlrq"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.hmon_jlrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
    </el-table>

    <!-- 查询对话框   -->
    <el-dialog
      title="查询"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="650px"
      append-to-body
    >
      <el-form
        :model="tableData.queryParams"
        ref="queryForm"
        label-width="75px"
      >
        <el-col :span="24">
          <el-form-item label="综合查询" prop="hmonWldm">
            <el-input v-model="tableData.queryParams.hmonWldm"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="查询日期">
            <el-date-picker
              v-model="tableData.queryParams.hmonJlrq"
              type="date"
              value-format="yyyy-MM-dd"
              clearable
              style="width: 100%"
            ></el-date-picker>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { historyMonMstrReport } from "@/api/money/monMstr";
import mixin from "@/mixins/common";

export default {
  name: "PriceReport",
  mixins: [mixin.unitFlagOptions, mixin.allStorageOptions],
  data() {
    return {
      // 遮罩层
      loading: true,
      exportLoading: false,
      openSearch: false,
      tableData: {
        rows: [],
        total: 0,
        queryParams: {
          pageNum: 1,
          pageSize: 40,
          hmonJlrq: undefined,
          hmonWldm: undefined,
        },
      },
      // 建立日期时间范围
      dateRange: [
        this.$moment().startOf("month").format(),
        this.$moment().endOf("month").format(),
      ],
    };
  },
  created() {
    this.getList();
  },

  methods: {
    /** 查询来料入库批退率列表 */
    getList() {
      this.loading = true;
      this.tableData.queryParams.pageNum = 1;
      historyMonMstrReport(this.tableData.queryParams).then((response) => {
        this.tableData.rows = response.rows;
        this.tableData.total = response.rows.total;
        this.loading = false;
      });
    },
    //load
    load() {
      if (
        this.tableData.queryParams.pageNum <
        Math.ceil(this.tableData.total / this.tableData.queryParams.pageSize)
      ) {
        this.tableData.queryParams.pageNum++;
        historyMonMstrReport(this.tableData.queryParams).then((response) => {
          this.tableData.rows = this.tableData.rows.concat(response.rows);
          this.tableData.total = response.total;
          this.loading = false;
        });
      }
      return 0;
    },
    // 取消按钮
    cancel() {
      this.openSearch = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
      this.openSearch = false;
    },
    /** 导出按钮操作 */
    handleExport() {
      // return YpService.getExportYp(this.queryParams).then((res) => this.download(res.msg))
    },
  },
};
</script>

<style lang="scss" scoped></style>
